package com.ny.mapper;

import com.ny.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from user")
    List<User> findAll();

    @Select("select  * from  user where  username= #{username} and password =#{password}")
    public User findUser(@Param("username") String username, @Param("password") String password) ;

    // 添加用户(用于注册)
    @Insert("INSERT INTO user(username, password, nickname, phone, email, is_active, created_time) VALUES(#{username}, #{password}, #{nickname}, #{phone}, #{email}, 1, NOW())")
    public int addUser(User user);
    // 查询邮箱是否存在
    @Select("SELECT count(*) FROM user WHERE email = #{email}")
    public int findUserByEmail(String email);

    @Update("UPDATE user SET password = #{password} WHERE email = #{email}")
    public int updateUser(@Param("email") String email, @Param("password") String password);
}